package com.szxb.facebus;

import android.animation.ObjectAnimator;
import android.animation.ValueAnimator;
import android.view.View;
import android.view.animation.LinearInterpolator;
import android.widget.TextView;

import com.szxb.facebus.base.BaseActivity;
import com.szxb.facebus.db.entity.bean.QRScanMessage;
import com.szxb.facebus.net.http.RxBaseRequest;
import com.szxb.facebus.util.basics.AppUtils;

import java.util.List;

public class MainActivity extends BaseActivity {

    private View scan_line;
    private ValueAnimator mScanAnimator;
    private TextView version;

    @Override
    protected int rootView() {
        return R.layout.activity_main;
    }

    @Override
    protected void initView() {
        super.initView();
        scan_line = findViewById(R.id.scan_line);

        version = findViewById(R.id.version);
        version.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
        List<RxBaseRequest> taskList = AppUtils.getScanInit();
        AppUtils.run(taskList, null);


    }

    @Override
    protected void initData() {


    }

    @Override
    protected void message(QRScanMessage message) {

    }

    @Override
    protected void onStop() {
        super.onStop();
        mScanAnimator.cancel();
        mScanAnimator = null;
    }

    @Override
    protected void onPause() {
        super.onPause();
        mScanAnimator.cancel();
        mScanAnimator = null;
    }


    @Override
    public void onWindowFocusChanged(boolean hasFocus) {
        super.onWindowFocusChanged(hasFocus);
        if (mScanAnimator == null) {
            mScanAnimator = ObjectAnimator.ofFloat(scan_line, "translationY", -100, 100).setDuration(1100);
            mScanAnimator.setInterpolator(new LinearInterpolator());
            mScanAnimator.setRepeatCount(ValueAnimator.INFINITE);
            mScanAnimator.setRepeatMode(ValueAnimator.REVERSE);
            mScanAnimator.start();
        }

    }


}
